package cn.gok.controller;

import cn.gok.service.impl.BugServiceImpl;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/api/bug/")
public class BugController {
    @Autowired(required = false)
    private BugServiceImpl bugServiceImpl;
    //Bug页面
    @RequestMapping("/show")
    @ResponseBody
    public JSONObject show(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("searchKey",json.getString("searchKey"));
//        map.put("start",json.getInteger("start"));
//        map.put("pagesize",json.getInteger("pagesize"));
        JSONObject result =new JSONObject();
        result.put("data",bugServiceImpl.show(map));
        result.put("total",bugServiceImpl.show(map).size());
        return result;
    }
    //添加
    @RequestMapping("/add")
    @ResponseBody
    public JSONObject add(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("ip",json.getString("ip"));
        map.put("port",json.getString("port"));
        map.put("content",json.getString("content"));
        map.put("type",json.getString("type"));
        JSONObject result=new JSONObject();
        result.put("code",bugServiceImpl.add(map));
        return result;
    }
    //删除
    @RequestMapping("/del")
    @ResponseBody
    public JSONObject del(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("id",json.getInteger("id"));
        JSONObject result=new JSONObject();
        result.put("code",bugServiceImpl.del(map));
        return result;
    }
    //修改
    @RequestMapping("/re")
    @ResponseBody
    public JSONObject re(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("ip",json.getString("ip"));
        map.put("port",json.getString("port"));
        map.put("content",json.getString("content"));
        map.put("type",json.getString("type"));
        JSONObject result=new JSONObject();
        result.put("code",bugServiceImpl.updata1(map));
        return result;
    }
    //下发
    @RequestMapping("/down")
    @ResponseBody
    public JSONObject down(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("ids",json.getJSONArray("ids"));
        map.put("userid",json.getInteger("userid"));
        JSONObject result=new JSONObject();
        result.put("code",bugServiceImpl.updata2(map));
        return result;
    }
    //个人漏洞
    @RequestMapping("/usershow")
    @ResponseBody
    public JSONObject usershow(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("searchKey",json.getInteger("searchKey"));
//        map.put("start",json.getInteger("start"));
//        map.put("pagesize",json.getInteger("pagesize"));
        JSONObject result =new JSONObject();
        result.put("data",bugServiceImpl.show1(map));
        result.put("total",bugServiceImpl.show1(map).size());
        return result;
    }
    //详情
    @RequestMapping("/details")
    @ResponseBody
    public JSONObject details(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("id",json.getInteger("id"));
//        map.put("start",json.getInteger("start"));
//        map.put("pagesize",json.getInteger("pagesize"));
        JSONObject result =new JSONObject();
        result.put("data",bugServiceImpl.details(map));
        result.put("total",bugServiceImpl.details(map).size());
        return result;
    }
    //漏洞处理
    @RequestMapping("/userre")
    @ResponseBody
    public JSONObject userre(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("id",json.getInteger("id"));
        map.put("solveCont",json.getString("solveCont"));
        map.put("user",json.getString("user"));
        map.put("state",json.getString("state"));
        map.put("userid",json.getInteger("userid"));
        JSONObject result=new JSONObject();
        result.put("code",bugServiceImpl.updata(map));
        return result;
    }
    //已完成
    @RequestMapping("/completeshow")
    @ResponseBody
    public JSONObject completeshow(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("searchKey",json.getString("searchKey"));
//        map.put("start",json.getInteger("start"));
//        map.put("pagesize",json.getInteger("pagesize"));
        JSONObject result =new JSONObject();
        result.put("data",bugServiceImpl.show1(map));
        result.put("total",bugServiceImpl.show1(map).size());
        return result;
    }
    @RequestMapping("/show2")
    @ResponseBody
    public JSONObject show2(@RequestBody JSONObject json){
        JSONObject result =new JSONObject();
        result.put("data",bugServiceImpl.show2());
        return result;
    }
    @RequestMapping("/re2")
    @ResponseBody
    public JSONObject re2(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("user",json.getString("name"));
        map.put("userID",json.getString("id2"));
        map.put("id",json.getString("id"));
        JSONObject result =new JSONObject();
        result.put("code",bugServiceImpl.re(map));
        return result;
    }
    @RequestMapping("/re3")
    @ResponseBody
    public JSONObject re3(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("solveCont",json.getString("solveCont"));
        map.put("id",json.getString("id"));
        JSONObject result =new JSONObject();
        result.put("code",bugServiceImpl.re3(map));
        return result;
    }
    @RequestMapping("/re4")
    @ResponseBody
    public JSONObject re4(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("state",json.getString("state"));
        map.put("id",json.getString("id"));
        JSONObject result =new JSONObject();
        result.put("code",bugServiceImpl.re4(map));
        return result;
    }
    @RequestMapping("/my")
    @ResponseBody
    public JSONObject my(@RequestBody JSONObject json){
        Map<String,Object> map=new HashMap<>();
        map.put("user",json.getString("user"));
        JSONObject result =new JSONObject();
        result.put("data",bugServiceImpl.my(map));
        return result;
    }
}
